﻿using DAQ.Common;
using System;
using System.Collections.Generic;

namespace DAQ.PROTOCOL
{
    public class ADVANCED_TENSION_READ
    {
        byte[] _bytes = new byte[74];
        public static byte[] GetSendBytes(byte Addr)
        {
            return BasicUtil.AppendChecksum(Addr, 0x3A);
        }
        public ADVANCED_TENSION_READ(byte[] srcBytes)
        {
            Array.Copy(srcBytes, _bytes, srcBytes.Length);
        }
        public Dictionary<string, string> AllValues
        {
            get
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();
                foreach (var a in this.GetType().GetProperties())
                {
                    if (a.Name != "AllValues")
                    {
                        dictionary.Add(a.Name, a.GetValue(this).ToString());
                    }
                }
                return dictionary;
            }
        }

        public int MAIN_TENSION_1 { get { return _bytes.SubByte(0, 2).BytesToInteger(); } }
        public int MAIN_TENSION_2 { get { return _bytes.SubByte(2, 2).BytesToInteger(); } }
        public int MAIN_TENSION_3 { get { return _bytes.SubByte(4, 2).BytesToInteger(); } }
        public int MAIN_TENSION_4 { get { return _bytes.SubByte(6, 2).BytesToInteger(); } }
        public int INC_DEC_TENSION { get { return _bytes.SubByte(8, 2).BytesToInteger(); } }
        public int RECOVERY_TENSION { get { return _bytes.SubByte(10, 2).BytesToInteger(); } }
        public int METER_TENSION_1 { get { return _bytes.SubByte(12, 4).BytesToInteger(); } }
        public int METER_TENSION_2 { get { return _bytes.SubByte(16, 4).BytesToInteger(); } }
        public int METER_TENSION_3 { get { return _bytes.SubByte(20, 4).BytesToInteger(); } }
        public int METER_TENSION_4 { get { return _bytes.SubByte(24, 4).BytesToInteger(); } }
        public int METER_INCDEC{get { return _bytes.SubByte(28, 4).BytesToInteger(); }}
        public int METER_TARGET { get { return _bytes.SubByte(32, 4).BytesToInteger(); } }
        public int TENSION_ERROR { get { return _bytes.SubByte(36, 2).BytesToInteger(); } }
        public int TIME_ALARM { get { return _bytes.SubByte(38, 2).BytesToInteger(); } }
        public int TAKE_UP_ARM_SETPOINT { get { return _bytes.SubByte(40, 2).BytesToInteger(); } }
        public int CWF2000_INTERFACE_TYPE { get { return _bytes.SubByte(42, 1).BytesToInteger(); } }
        public int RAMP_UP { get { return _bytes.SubByte(43, 2).BytesToInteger(); } }
        public int RAMP_DOWN { get { return _bytes.SubByte(45, 2).BytesToInteger(); } }
        public int APPLICATION { get { return _bytes.SubByte(47, 1).BytesToInteger(); } }
        public int SPRING_FORCE_1 { get { return _bytes.SubByte(49, 2).BytesToInteger(); } }
        public int SPRING_FORCE_2 { get { return _bytes.SubByte(51, 2).BytesToInteger(); } }
        public int SPRING_FORCE_3 { get { return _bytes.SubByte(53, 2).BytesToInteger(); } }
        public int SPRING_FORCE_4 { get { return _bytes.SubByte(55, 2).BytesToInteger(); } }
        public int SPEED_CHANGE_12 { get { return _bytes.SubByte(57, 2).BytesToInteger(); } }
        public int SPRING_FORCE_23 { get { return _bytes.SubByte(59, 2).BytesToInteger(); } }
        public byte TENSION_ACTIVATION { get { return _bytes.SubByte(61, 1)[0]; } }
        public byte SPRING_AND_TARGET_ACTIVATION { get { return _bytes.SubByte(62, 1)[0]; } }
        public int AD_END_SCALE { get { return _bytes.SubByte(63, 2).BytesToInteger(); } }
        public bool TENSION_ERROR_ENABLED { get { return (TENSION_ACTIVATION & (1 << 0)) > 0; } }
        public bool TENSION_2_ENABLED { get { return (TENSION_ACTIVATION & (1 << 1)) > 0; } }
        public bool TENSION_3_ENABLED { get { return (TENSION_ACTIVATION & (1 << 2)) > 0; } }
        public bool TENSION_4_ENABLED { get { return (TENSION_ACTIVATION & (1 << 3)) > 0; } }
        public bool TARGET_ENABLED { get { return (SPRING_AND_TARGET_ACTIVATION & (1 << 0)) > 0; } }
        public bool SPRING_2_FORCE_ENABLED { get { return (SPRING_AND_TARGET_ACTIVATION & (1 << 1)) > 0; } }
        public bool SPRING_3_FORCE_ENABLED { get { return (SPRING_AND_TARGET_ACTIVATION & (1 << 2)) > 0; } }
        public bool SPRING_4_FORCE_ENABLED { get { return (SPRING_AND_TARGET_ACTIVATION & (1 << 3)) > 0; } }
    }
}
    

    


